<template>
  <div>
    <!-- 设置估价修改 -->
    <GuaranteeValuationUpdate :khmcid="queryParams.khmcid" ref="openGuaranteeValuationUpdate" @refresh="refresh"></GuaranteeValuationUpdate>
    <!-- 设置估价批量修改 -->
    <GuaranteeValuationPatchUpdate ref="openGuaranteeValuationPatchUpdate" @refresh="refresh"></GuaranteeValuationPatchUpdate>
    <!-- 设置估价货物详情 -->
    <GuaranteeValuationGoodsDetails ref="openGuaranteeValuationGoodsDetails" @refresh="refresh"></GuaranteeValuationGoodsDetails>
    
    <!-- 设置估价对话框 -->
    <el-dialog :title="rowData.allName" :visible.sync="openGuaranteeValuation" width="1200px" append-to-body :destroy-on-close="true" :before-close="beforeClose">
      <el-form ref="form" @submit.native.prevent :model="queryParams" :rules="rules" label-width="80px" :inline="true">
        <el-form-item label="物品规格" prop="name">
          <el-input
            v-model="queryParams.spzs"
            placeholder="请输入物品规格"
            clearable
             @keyup.enter.native="enterClick"
          />
        </el-form-item>
          <el-form-item label="品牌" prop="name">
          <el-input
            v-model="queryParams.spcd"
            placeholder="请输入品牌"
            clearable
             @keyup.enter.native="enterClick"
          />
        </el-form-item>
        <el-form-item >
          <el-checkbox label="显示所有用户" true-label="1" v-model="queryParams.ally3" @change="getList"></el-checkbox>
          <el-checkbox label="未设置货物估值" true-label="1" v-model="queryParams.danjia0" @change="getList"></el-checkbox>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
        <el-row :gutter="10" class="mb8">
          <!-- <el-col :span="1.5">
            <el-button  type="primary" plain size="mini" @click="handleBatchUpdate">批量修改</el-button>
          </el-col> -->
          <el-col :span="1.5">
            <el-button type="primary" plain size="mini" @click="handleExport" v-hasPermi="['zhcloud:hwdb:export']">导出为Excel</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="primary" plain size="mini" @click="handleGoodsDetail" v-hasPermi="['zhcloud:hwdb:list']">货物详情</el-button>
          </el-col>
        </el-row>
        <el-table
          :data="setUpAnEstimateList"
          row-key="id"
          @selection-change="handleSelectionChange"
        >
          <af-table-column type="selection" width="50" align="center" />
          <af-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150" fixed="left">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="handleValuationUpdate(scope.row)"
              v-hasPermi="['zhcloud:hwdb:list']"
            >估价修改</el-button>
          </template>
          </af-table-column>
          <af-table-column prop="zje" label="货物估值总价" fixed="left"></af-table-column>
          <af-table-column prop="jine" label="货物估值单价"></af-table-column>
          <af-table-column prop="spjs" label="件数"></af-table-column>
          <af-table-column prop="spsl" label="重量(吨)"></af-table-column>
          <af-table-column prop="spzs" label="物品规格"></af-table-column>
          <af-table-column prop="spcd" label="品牌"></af-table-column>
          <af-table-column prop="allName" label="物品公司"></af-table-column>
        </el-table>
      </el-form>
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="pageNum"
          :limit.sync="pageSize"
          @pagination="getList"
        />
    </el-dialog>
  </div>
 
</template>

<script>
import { setUpAnEstimate } from "@/api/storage/guarantee";
import GuaranteeValuationUpdate from "./guaranteeValuationUpdate.vue"
import GuaranteeValuationPatchUpdate from "./guaranteeValuationPatchUpdate.vue"
import GuaranteeValuationGoodsDetails from './guaranteeValuationGoodsDetails.vue'

export default {
  name: "GuaranteeValuation",
  components: { GuaranteeValuationUpdate, GuaranteeValuationPatchUpdate, GuaranteeValuationGoodsDetails },
  data() {
    return {
      //行数据
      rowData:{},
      // 显示搜索条件
      showSearch: true,
      // 重新渲染表格状态
      refreshTable: true,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      //弹窗状态
      openGuaranteeValuation: false,
      // 查询参数
      queryParams: {
        ally3: "",
        bptm: "",
        ckcw: "",
        danjia0: "",
        dbnum: "",
        isBa: "",
        khmcid: "",
        khpb: 0,
        shopId: 0,
        spcd: "",
        spckidis: [],
        spckmc: "",
        spgh: "",
        spzs: "",
        ssrqid: "",
        downloadType:"json"
      },
      //估价详情列表
      setUpAnEstimateList:[],
      //估价详情
      updatePrePriceRow:{},
      updatePatchPriceArray: [],
      //页数
      pageSize: 10,
      //页码
      pageNum:1,
      // 总条数
      total: 0,
     
    };
  },
  methods: {
    /**获取估价货物详情列表 */
    getList() {
      setUpAnEstimate(this.queryParams, {pageNum:this.pageNum, pageSize:this.pageSize}).then(response => {
        const rows = response.rows
        for(let i in rows) {
          rows[i].id = i
        }
        this.setUpAnEstimateList = this.handleTree(rows, "id");
        this.total = response.total;
      });
    },
    
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },

    /** 批量修改 */
    handleBatchUpdate() {
      this.$refs.openGuaranteeValuationPatchUpdate.open(this.updatePatchPriceArray)      
    },

    /** 导出为Excel */
    handleExport() {
       this.download('/storage/hwdb/export2', this.queryParams, `user_${new Date().getTime()}.xlsx`)
    },

    /** 货物详情 */
    handleGoodsDetail() {
      this.$refs.openGuaranteeValuationGoodsDetails.open(this.queryParams.khmcid)
    },

    /** 估价修改 */
    handleValuationUpdate(row) {
      this.$refs.openGuaranteeValuationUpdate.open(row, this.queryParams.khmcid)
    },

     // 多选框选中数据
    handleSelectionChange(selection) {
      this.updatePatchPriceArray = selection
    },

    //刷新
    refresh() {
      this.getList()
    },
  
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        ally3: "",
        bptm: "",
        ckcw: "",
        danjia0: "",
        dbnum: "",
        isBa: "",
        khmcid: this.queryParams.khmcid,
        khpb: 0,
        shopId: 0,
        spcd: "",
        spckidis: [],
        spckmc: "",
        spgh: "",
        spzs: "",
        ssrqid: ""
      }
      this.resetForm("queryForm");
      this.handleQuery();
    },
       /**enter键触发 */
    enterClick(e) {
      this.getList()
    },

    /**改变窗口状态 */
    changeGuaranteeValuation() {
      this.openGuaranteeValuation = !this.openGuaranteeValuation;
    },

    //关闭弹窗
    beforeClose(done) {
      this.changeGuaranteeValuation()
      this.$emit('refresh', true)
      done()
    },
    /**打开弹窗 */
    open(row) {
      this.resetQuery()
      this.changeGuaranteeValuation()
      this.rowData = row
      this.queryParams.khmcid = row.id
      this.getList()
    }
  }
};
</script>
